﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using GameBase;

namespace GalaxyPresident
{
    public abstract class PlanetEntity : PlanetObjectOwner
    {
        private static Texture2D explosionTexture = Constant.content.Load<Texture2D>(@"Resources/Ammo/groundExplosion");
        protected float _height;
        private int blockIndex;
        protected List<Task> availableTasks  = new List<Task>();
        protected int level = 0;

        public List<Task> AvailableTasks
        {
            get { return availableTasks; }
            set { availableTasks = value; }
        }

        public int BlockIndex
        {
            get { return blockIndex; }
            set { blockIndex = value; }
        }

        public float Height
        {
            get { return _height; }
            set { _height = value; }
        }

        public PlanetEntity(Planet planet)
            : base(planet)
        {
            _explosion = new VisibleObject(explosionTexture, 2, 5);
            _explosion.Sprite.SetOriginPosition(ORIGIN_POSITION.Center);
            _explosion.Depth = 0.08f;
            _explosion.Sprite.IsPlayOneTime = true;
            _explosion.Sprite.Delay = 150;
            _explosion.Scale = Constant.scalePlanetEntity;
            InitAvailableTasks();
        }
        protected virtual void InitAvailableTasks()
        {

        }
        protected void initSprites(Planet planet)
        {
            sprite_s.SetOriginPosition(ORIGIN_POSITION.MidBottom);
            //if (planet.TeamOwner == null)
            //    sprite_s.Color = Color.Black;
            //else
                //sprite_s.Color = planet.TeamOwner.TeamColor;
            
            updateSpriteSColor();
                
            AddSprite(sprite_s);

            sprite.SetOriginPosition(ORIGIN_POSITION.MidBottom);
            sprite.Color = Color.White;
            AddSprite(sprite);
            depth = 0.9f;
        }

        protected virtual void updateSpriteSColor()
        {
            
        }

        protected override void removeObjectWhenDestroy()
        {
            PlanetOwner.Blocks[blockIndex].Entity = null;
        }

        public virtual bool isCommonEntity()
        {
            return false;
        }

        public virtual string getObjectName()
        {
            return "";
        }

        public virtual void startUpdatePlanetInfo()
        {
        }

        public virtual float getEconomicIncreaseAmount()
        {
            return 0;
        }

        public override void UpdateInfo(GameTime gameTime)
        {
            foreach (Task task in availableTasks)
                task.UpdateInfo(gameTime);
        }
    }
}
